// ----------------------------------------------------------------------------
// Copyright (C) 2012 by Daniel Gro_er
// 
// This code is under GNU LGPL 3.0, see http://www.gnu.org/licenses/lgpl.html
// For further information and questions, visit:
// http://code.google.com/p/beauty-parser/
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Beauty.Tools
{
    /// <summary>
    /// This class provides a language by getting all types implementing INode from an assembly
    /// where the namespace of the types is constrained to start with a specific portion.
    /// </summary>
    public class NamespaceLanguageProvider : AssemblyLanguageProvider
    {
        /// <summary>
        /// Create a new instance.
        /// </summary>
        /// <param name="languageAssembly">The assembly holding all INode implementations.</param>
        /// <param name="namespaceName">The namespace under wich all INode implementations must lay.</param>
        public NamespaceLanguageProvider(Assembly languageAssembly, string namespaceName)
            : base(languageAssembly)
        {
            NamespaceName = namespaceName;
        }

        /// <summary>
        /// The namespace under wich all INode implementations must lay.
        /// </summary>
        public readonly string NamespaceName;

        /// <summary>
        /// Get the set of abstract syntax tree node types that define a language.
        /// </summary>
        public override IEnumerable<Type> AbstractSyntaxTreeNodes
        {
            get
            {
                return base.AbstractSyntaxTreeNodes.Where((t) => t.Namespace.StartsWith(NamespaceName));
            }
        }
    }
}
